package uk.ac.manchester.cs.owl.ontologyrepositoryapi.tools;

import uk.ac.manchester.cs.owl.ontologyrepositoryapi.BioPortalOntologyRepository;
import uk.ac.manchester.cs.owl.ontologyrepositoryapi.OntologyRepositoryEntry;

/**
 * Author: Matthew Horridge<br>
 * The University of Manchester<br>
 * Bio-Health Informatics Group<br>
 * Date: 12/03/2011
 */
public class BioPortalTools {

    private static final String DOWNLOAD_SWITCH = "download";

    private static final String LIST_SWITCH = "list";

    public static void main(String[] args) {
        CommandLineArgs cmdArgs = new CommandLineArgs(args);
        if(cmdArgs.hasSwitch(DOWNLOAD_SWITCH)) {
            downloadOntologies(args[1]);
        }
        else if(cmdArgs.hasSwitch(LIST_SWITCH)) {
            listOntologies(args[1]);
        }
        else {
            System.out.println("Expected one of:");
            System.out.println("\t-" + DOWNLOAD_SWITCH + " (Downloads ontologies from bioportal.  Each ontology is downloaded into a separate folder.  The imports closure of each ontology is merged into a single OWL/XML, with each axiom annotated with its source ontology.)");
            System.out.println("\t-" + LIST_SWITCH + " (Lists the ontologies in bioportal)");
            System.out.println("You also need to specify the API key for BioPortal");
        }
    }

    private static void downloadOntologies(String apiKey) {
        DownloadOntologies downloadOntologies = new DownloadOntologies(apiKey);
        downloadOntologies.download();
    }

    private static void listOntologies(String apiKey) {
        BioPortalOntologyRepository repository = new BioPortalOntologyRepository(apiKey);
        int count = 0;
        for(OntologyRepositoryEntry entry : repository.getEntries()) {
            if (entry.isOWLCompatibleFormat()) {
                System.out.println(entry);
                count++;
            }
        }
        System.out.println(count + " ontologies");
    }
}
